﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DemoObject;
using BusinessObjects;

public partial class Module_Video_Controls_VideoList : System.Web.UI.UserControl
{
    public string VideoCategoryTextId { get; set; }
    public Guid? VideoCategoryId { get; set; }
    public string VideoCategoryName { get; set; }
    public int PageIndex
    {
        get
        {
            if (Request["page"] != null)
                return int.Parse(Request["page"].ToString());
            return 1;
        }
    }
    private const int PageSize = 20;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["VideoCategoryTextId"] != null)
            {
                VideoCategoryTextId = Request["VideoCategoryTextId"];
                TblVideoCategories item = TblVideoCategoriesRepository.CreateInstant().SelectOne(VideoCategoryTextId);
                if (item != null)
                {
                    VideoCategoryId = item.Id;
                    VideoCategoryName = item.Name;
                }
                else VideoCategoryId = null;
                SetTitle(item);
            }
            HashSet<string> hs = new HashSet<string>();
            hs.Add("CreatedDate DESC");
            int count = 0;
            rpt.DataSource = TblVideoRepository.CreateInstant().SelectListItem(null, VideoCategoryId, null, "", "", "", null, true, null, PageIndex, PageSize, out count, hs);
            rpt.DataBind();
            smartPager.PageSize = PageSize;
            smartPager.QueryStringKey = "page";
            smartPager.RowCount = count;
            smartPager.UrlFormatString = UrlBuilder.UrlVideoListPaging(VideoCategoryTextId);
            smartPager.Visible = count > PageSize;
        }
    }
    void SetTitle(TblVideoCategories _item)
    {
        string title = _item.Name;
        string description = _item.Name;
        string keywords = _item.Name;
        MasterPage _page = this.Page.Master;
        HTT.Utility.WebUtility.SetPage(title, description, keywords, _page);
    }
}
